package org.hard.model.structure.decorator;

/**
 * @author: 王林博
 * @date: 2023年07月13日 17:56
 */
public class Demo {

    /**
     // 抽象组件
     public interface Text {
        void write(String content);
     }

     // 具体组件
     public class BasicText implements Text {
         public void write(String content) {
            System.out.println("Basic Text: " + content);
         }
     }

     // 抽象装饰器
     public abstract class TextDecorator implements Text {
         protected Text text;

         public TextDecorator(Text text) {
            this.text = text;
        }

        public void write(String content) {
            text.write(content);
        }
     }

     // 具体装饰器
     public class UppercaseTextDecorator extends TextDecorator {
         public UppercaseTextDecorator(Text text) {
            super(text);
         }

         public void write(String content) {
             String uppercaseContent = content.toUpperCase();
             super.write(uppercaseContent);
         }
     }

     // 使用装饰器模式
     public class Main {
         public static void main(String[] args) {
             Text text = new BasicText();
             Text decoratedText = new UppercaseTextDecorator(text);
             decoratedText.write("Hello, World!");
         }
     }
     */
}
